package com.stedu.service.Impl;

import com.stedu.bean.Games;
import com.stedu.exception.SteduException;
import com.stedu.mapper.GamesMapper;
import com.stedu.service.GamesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class GamesServiceImpl implements GamesService {
    @Autowired
    private GamesMapper gamesMapper;
    @Override
    public long findCount(String gname, String gnum)  {
        return gamesMapper.selectCount(gname, gnum);
    }

    @Override
    public boolean addemp(Games games)  {
        //版号
        String s = gamesMapper.selectMaxEno();
        int i = Integer.parseInt(s);
        s = i +1 +"";
        games.setGnum(s);
        //在职状态
        games.setEstate(1);
        return gamesMapper.addemp(games)==1?true:false;
    }

    @Override
    public boolean delete(Long gid)  {
        return gamesMapper.updateestate(gid, 2)==1?true:false;
    }

    @Override
    public Games selectById(Long gid)  {
        return gamesMapper.selectByEid(gid);
    }

    @Override
    public boolean update(Games games) throws  SteduException {
        if (gamesMapper.selectByEid(games.getGid())==null){
            throw  new SteduException("该游戏不存在，无法删除");
        }
        return gamesMapper.updateemp(games)==1?true:false;
    }

    @Override
    public List<Games> selecyAll(String gname,  String gnum)  {
        return gamesMapper.selectAll(gname,gnum);
    }

    @Override
    public List<Map<String, Object>> findrevenue() {
        return gamesMapper.selectrevenue();
    }
}
